# 阶段1：基础Jenkins镜像（合并到最终阶段）
#FROM jenkins:2.438
FROM jenkins/jenkins:2.452.3-lts-jdk17
USER root

# 配置APT源（×）
RUN echo "deb http://mirrors.aliyun.com/debian bookworm main" > /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main" >> /etc/apt/sources.list

# 安装基础依赖和.NET所需库（×）
RUN apt-get update && \
    apt-get install -y \
        libgdiplus \
        libc6 \
        libgcc-s1 \
        libgssapi-krb5-2 \
        libicu72 \
        liblttng-ust1 \
        libssl3 \
        libstdc++6 \
        zlib1g \
        # 补充额外依赖
        libunwind8 \
        libuuid1 \
    && rm -rf /var/lib/apt/lists/*

# 直接从SDK镜像复制完整.NET环境
COPY --from=172.30.32.171:7090/mcr.microsoft.com/dotnet/sdk:7.0 /usr/share/dotnet /usr/share/dotnet

# 修复符号链接
RUN ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet

# 验证权限
RUN chmod -R 755 /usr/share/dotnet && \
    chmod +x /usr/bin/dotnet

# 设置全局环境变量
ENV DOTNET_ROOT=/usr/share/dotnet \
    PATH="$PATH:/usr/share/dotnet"

# 切换用户前验证
RUN dotnet --info

USER jenkins

# 最终验证（以jenkins身份运行）
RUN dotnet --info